#include "Teacher.h"
#include <string.h>
#include <stdio.h>

void InitTeach(Teach *t, char *name, int age)
{
    t->age = age;
    t->size = 0;
    strcpy(t->Name,name);

}

void InsertStu(Teach *t, int id, char *StuName)
{
    if(t->size == StuSize)
    {
        printf("数组已满，不允许插入学生数据！\n");
        return;
    }
    InitStu(&t->s[t->size++],id,StuName);
}

void RmByIndex(Teach *t, int index)
{
    for(int i = index; i < t->size - 1;i++)
        t->s[i] = t->s[i+1];
    t->size--;
}

void RmStuByID(Teach *t, int id)
{
    for(int i = 0;i < t->size;i++)
    {
        if(t->s[i].id == id)
        {
            RmByIndex(t,i);
            i--;
        }
    }
}

void RmStuByName(Teach *t, char *StuName)
{
    for(int i = 0;i < t->size;i++)
    {
        if(strcmp(t->s[i].Name,StuName) == 0)
        {
            RmByIndex(t,i);
            i--;
        }
    }
}

Stu *FindStuByName(Teach *t, char *StuName)
{
    for(int i = 0;i < t->size;i++)
    {
        if(strcmp(t->s[i].Name,StuName) == 0)
        {
            return &t->s[i];
        }
    }
    return NULL;
}

void PrintTeach(Teach *t)
{
    printf("老师姓名:%s 年龄：%d\n",t->Name,t->age);
    printf("学生信息：\n");
    for(int i = 0;i < t->size;i++)
    {
        PrintStu(&t->s[i]);
    }
}
